package org.apache.james.mime4j.field;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.james.mime4j.field.address.AddressList;
import org.apache.james.mime4j.field.address.Mailbox;
import org.apache.james.mime4j.field.address.MailboxList;
import org.apache.james.mime4j.field.address.parser.ParseException;

public class MailboxField extends Field
{
  static Class class$org$apache$james$mime4j$field$MailboxField$Parser;
  private final Mailbox mailbox;
  private final ParseException parseException;

  protected MailboxField(String paramString1, String paramString2, String paramString3, Mailbox paramMailbox, ParseException paramParseException)
  {
    super(paramString1, paramString2, paramString3);
    this.mailbox = paramMailbox;
    this.parseException = paramParseException;
  }

  static Class class$(String paramString)
  {
    Class localClass;
    try
    {
      localClass = Class.forName(paramString);
      return localClass;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new NoClassDefFoundError().initCause(localClassNotFoundException);
    }
  }

  public Mailbox getMailbox()
  {
    return this.mailbox;
  }

  public ParseException getParseException()
  {
    return this.parseException;
  }

  public static class Parser
  implements FieldParser
  {
    private static Log log;

    static
    {
      Class localClass;
      if (MailboxField.class$org$apache$james$mime4j$field$MailboxField$Parser == null)
      {
        localClass = MailboxField.class$("org.apache.james.mime4j.field.MailboxField$Parser");
        MailboxField.class$org$apache$james$mime4j$field$MailboxField$Parser = localClass;
      }
      while (true)
      {
        log = LogFactory.getLog(localClass);
        return;
        localClass = MailboxField.class$org$apache$james$mime4j$field$MailboxField$Parser;
      }
    }

    public Field parse(String paramString1, String paramString2, String paramString3)
    {
      Object localObject1 = null;
      Object localObject2 = null;
      try
      {
        MailboxList localMailboxList = AddressList.parse(paramString2).flatten();
        if (localMailboxList.size() > 0)
        {
          Mailbox localMailbox = localMailboxList.get(0);
          localObject1 = localMailbox;
        }
        return new MailboxField(paramString1, paramString2, paramString3, localObject1, (ParseException)localObject2);
      }
      catch (ParseException localParseException)
      {
        if (log.isDebugEnabled())
          log.debug("Parsing value '" + paramString2 + "': " + localParseException.getMessage());
        localObject2 = localParseException;
      }
    }
  }
}